package leetcode.Y2024M6.review;

import org.junit.Test;

import java.util.Arrays;

/**
 * 还是无法理解，脑袋里没图
 */
public class S80 {
    public int removeDuplicates(int[] nums) {
        return removeDuplicates(nums, 2);
    }

    private int removeDuplicates(int[] nums, int k) {
        int slow = 0;
        for (int fastVal : nums) {
            if (slow < k || nums[slow - k] != fastVal) {
                nums[slow++] = fastVal;
            }
        }
        return slow;
    }

    @Test
    public void test() {
        int[] nums = {1, 1, 1, 2, 2, 3};
        int i = removeDuplicates(nums);
        System.out.println(i);
        System.out.println(Arrays.toString(nums));
    }

    @Test
    public void test2() {
        int[] nums = {0, 0, 1, 1, 1, 1, 2, 3, 3};
        int i = removeDuplicates(nums);
        System.out.println(i);
        System.out.println(Arrays.toString(nums));
    }
}
